package com.ruoyi.iot.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.iot.domain.FacCommonMonitorField;
import com.ruoyi.iot.service.IFacCommonMonitorFieldService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备监控常见字段Controller
 * 
 * @author rww
 * @date 2024-06-17
 */
@RestController
@RequestMapping("/iot/field")
public class FacCommonMonitorFieldController extends BaseController
{
    @Autowired
    private IFacCommonMonitorFieldService facCommonMonitorFieldService;

    /**
     * 查询设备监控常见字段列表
     */
    @PreAuthorize("@ss.hasPermi('iot:field:list')")
    @GetMapping("/list")
    public TableDataInfo list(FacCommonMonitorField facCommonMonitorField)
    {
        startPage();
        List<FacCommonMonitorField> list = facCommonMonitorFieldService.selectFacCommonMonitorFieldList(facCommonMonitorField);
        return getDataTable(list);
    }
    /**
     * * 获取常规字段列表-不分页
    */
    @GetMapping("/noPageList")
    public AjaxResult noPageList(FacCommonMonitorField facCommonMonitorField)
    {
        List<FacCommonMonitorField> list = facCommonMonitorFieldService.selectFacCommonMonitorFieldList(facCommonMonitorField);
        return AjaxResult.success(list);
    }
    /**
     * 导出设备监控常见字段列表
     */
    @PreAuthorize("@ss.hasPermi('iot:field:export')")
    @Log(title = "设备监控常见字段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FacCommonMonitorField facCommonMonitorField)
    {
        List<FacCommonMonitorField> list = facCommonMonitorFieldService.selectFacCommonMonitorFieldList(facCommonMonitorField);
        ExcelUtil<FacCommonMonitorField> util = new ExcelUtil<FacCommonMonitorField>(FacCommonMonitorField.class);
        util.exportExcel(response, list, "设备监控常见字段数据");
    }

    /**
     * 获取设备监控常见字段详细信息
     */
    @PreAuthorize("@ss.hasPermi('iot:field:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(facCommonMonitorFieldService.selectFacCommonMonitorFieldById(id));
    }

    /**
     * 新增设备监控常见字段
     */
    @PreAuthorize("@ss.hasPermi('iot:field:add')")
    @Log(title = "设备监控常见字段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FacCommonMonitorField facCommonMonitorField)
    {
        return toAjax(facCommonMonitorFieldService.insertFacCommonMonitorField(facCommonMonitorField));
    }

    /**
     * 修改设备监控常见字段
     */
    @PreAuthorize("@ss.hasPermi('iot:field:edit')")
    @Log(title = "设备监控常见字段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FacCommonMonitorField facCommonMonitorField)
    {
        return toAjax(facCommonMonitorFieldService.updateFacCommonMonitorField(facCommonMonitorField));
    }

    /**
     * 删除设备监控常见字段
     */
    @PreAuthorize("@ss.hasPermi('iot:field:remove')")
    @Log(title = "设备监控常见字段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(facCommonMonitorFieldService.deleteFacCommonMonitorFieldByIds(ids));
    }
}
